package innerclassdemo;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2023-10-18
 * Time：21:16
 */
class OuterClass2 {
    public int data1 = 10;
    private int data2 = 20;
    public static int data3 = 30;

    /**
     * 1、实例化：如main函数内
     * 2、静态内部类中只能访问外部类的静态成员：
     * 解决：提供一个外部类对象
     */
    static class InnerClass {
        public int data4 = 40;
        private int data5 = 50;
        public static int data6 = 60;

        OuterClass2 out = new OuterClass2();
        InnerClass() {
            System.out.println("InnerClass()");
        }
        public void method() {
            System.out.println("innerclass的成员方法");
            System.out.println("外部成员变量");
            System.out.println(out.data1);
            System.out.println(out.data2);
            System.out.println(data3);
        }
    }
}
class Test {
    public int a = 19;
    public void test() {
        System.out.println("test()");
    }
}
public class TestDemo2 {
    public static void main(String[] args) {
        /**
         * 匿名内部类
         */
        new Test() {
            public void test1(){
                System.out.println("hhhhh");
            }
            @Override
            public void test(){
                System.out.println("重写");
            }
        }.test1();
    }
    public static void main1(String[] args) {
        //不需要实例外部类对象，使用频率比较高
        OuterClass2.InnerClass innerClass = new OuterClass2.InnerClass();
        innerClass.method();
    }
}
